<%--
  Created by IntelliJ IDEA.
  User: LMY
  Date: 2025/7/28
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>购票</title>

    <base href="<%=request.getContextPath() + "/"%>">
  </head>
  <body>
  <h1>北京-成都 火车票秒杀！</h1>

  <form id="secKillForm" action="secKillServlet" enctype="application/x-www-form-urlencoded">
    <input type="hidden" id="ticketNo" name="ticketNo" value="bj_cd"/>
    <input type="button" id="secKillBtn" name="secKillBtn" value="秒杀火车票【北京-成都】"/>
  </form>
  </body>

  <script type="text/javascript" src="script/jquery/jquery-3.6.0.min.js"></script>
  <script type="text/javascript">
    $(function() {
      $("#secKillBtn").click(function () {
        var url = $("#secKillForm").attr("action");
          $.post(url, //完整url http:localhost:8080/seckill/secKillServlet
              $("#secKillForm").serialize(),  //ticketNo=bj_cd
              function(data) {
                if (data === "false") {
                  alert("火车票已售完");
                  $("#secKillBtn").attr("disabled", true);
                }
                if (data === "true") {
                  alert("已售出一张");
                }
              }
          )
      })
    })
  </script>
</html>
